package com.baizhi.controller;

import com.baizhi.entity.User;
import com.baizhi.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;

@Controller
@RequestMapping("User")
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("queryPageAll")
    @ResponseBody
    public HashMap<String,Object> queryPageAll(Integer page,Integer rows){
        return userService.queryByPage(page, rows);
    }

    @ResponseBody
    @RequestMapping("edit")
    public String edit(User user, String  oper){
        String id = null;
        if(oper.equals("del")){
            userService.del(user);
        }
        if(oper.equals("add")){
            id = userService.add(user);
        }
        if(oper.equals("edit")){
            id = userService.update(user);
        }
        return id;
    }

    //文件上传
    @ResponseBody
    @RequestMapping("uploadUserHeadImg")
    public void uploadUserHeadImg(MultipartFile headImg, String id){
        userService.uploadUserHeadImgAliyun(headImg,id);
    }


    //数据导出
    @ResponseBody
    @RequestMapping("downloadAll")
    public void downloadAll(){
        //=======================前端另存为页面未添加，暂时将名称与路径写死
        userService.downloadAll("用户数据","用户数据1","C:\\Users\\21356\\Desktop\\testExcel.xls");
    }

    //男女分布
    @ResponseBody
    @RequestMapping("querySexCount")
    public HashMap<String,Object> querySexCount(){
        return userService.querySexCount();
    }

}
